package org.example;/*
 * title:
 * author:
 * date:
 * description:
 * */

import java.util.concurrent.*;

public class FutureThreadPool {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService threadPool = Executors.newFixedThreadPool(3);

        long start = System.currentTimeMillis();

        FutureTask futrueTask1 = new FutureTask(() -> {
            TimeUnit.MILLISECONDS.sleep(500);
            return "task1 over";
        });
        threadPool.submit(futrueTask1);

        FutureTask futrueTask2 = new FutureTask(() -> {
            TimeUnit.MILLISECONDS.sleep(300);
            return "task2 over";
        });
        threadPool.submit(futrueTask2);

        System.out.println(futrueTask1.get());
        System.out.println(futrueTask2.get());

        TimeUnit.MILLISECONDS.sleep(300);
        long end = System.currentTimeMillis();

        System.out.println(end - start);

        threadPool.shutdown();
    }
}
